package com.fingard.dsp.bank.directbank.chinaums01;

import com.alibaba.fastjson.JSON;
import com.fingard.FGBiz;
import com.fingard.constant.Format;
import com.fingard.crypto.DigestHelper;
import com.fingard.dsp.bank.directConfig.ActSetItem;
import com.fingard.dsp.bank.directbank.DirectBase;
import com.fingard.dsp.bank.directbank.chinaums01.util.EncryptUtils;
import com.fingard.dsp.bank.directbank.chinaums01.util.SignUtil;
import com.fingard.net.URLHelper;
import com.fingard.text.StringHelper;
import com.fingard.util.DateHelper;
import com.fingard.util.SortHelper;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.config.ConnectionConfig;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import javax.net.ssl.*;
import java.io.*;
import java.net.*;
import java.nio.charset.Charset;
import java.security.InvalidKeyException;
import java.security.KeyStore;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.text.SimpleDateFormat;
import java.util.*;

public class ChinaUMS01Base extends DirectBase {
    public String getCharset() {
        return getBankConfig().getCharset("UTF-8");
    }

    public String getPOSCharset() {
        return getBankConfig().getCharset("GBK", "pos");
    }

    protected String getCharset(String p_def, String p_for) {
        return getBankConfig().getCharset(p_def, p_for);
    }

    /**
     * 消息来源
     */
    protected String getMsgSrc() {
        return getBankConfig().getValueAsString("msgSrc");
    }

    /**
     * 终端号
     */
    protected String getTerminalNum() {
        return getBankConfig().getValueAsString("terminalNum");
    }

    /**
     * 生成随机字符串
     *
     * @return
     * @throws Exception
     */
    protected String get_nonce_str() throws Exception {
        String time_stamp = DateHelper.getSecsFrom1970();
        Random random = new Random();
        long randLong = random.nextLong();
        randLong = random.nextLong();
        String nonce_str = time_stamp + String.format("%20d", randLong);
        nonce_str = DigestHelper.cryptoMD5RetHexStr(nonce_str.getBytes());
        return nonce_str;
    }

    protected String post(String p_url, String p_reqStr, String p_reqToken, boolean p_isRealAuth) throws Exception {
        String tmpStrRet = "";

        URL url = null;
        HttpURLConnection connection = null;
        BufferedReader reader = null;

        try {
            url = URLHelper.getUrl(p_url);//new URL(p_url);
            boolean enableProxy = FGBiz.dspCenter.dspSet.enableProxy;
            if(enableProxy){
                String proxyIP = FGBiz.dspCenter.dspSet.proxyIP;
                int proxyPort = Integer.parseInt(FGBiz.dspCenter.dspSet.proxyPort);

                SocketAddress sa = new InetSocketAddress(proxyIP, proxyPort);
                Proxy proxy = new Proxy(Proxy.Type.HTTP, sa);
                connection = (HttpURLConnection) url.openConnection(proxy);
            } else {
                connection = (HttpURLConnection) url.openConnection();
            }

            connection.setDoOutput(true);
            connection.setDoInput(true);
            connection.setRequestMethod("POST");
            connection.setUseCaches(false);
            connection.setInstanceFollowRedirects(true);

            if (p_isRealAuth == true) {
                connection.setRequestProperty("Authorization", p_reqToken);//授权
            }

            connection.setRequestProperty("Content-Type", "application/json;charset=" + getCharset() + "");
            connection.setRequestProperty("Accept", "application/json");
            connection.connect();

            OutputStream out = connection.getOutputStream();
            out.write(p_reqStr.getBytes(getCharset()));
            out.flush();
            out.close();

            reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), getCharset()));

            String lines;
            StringBuffer sb = new StringBuffer();
            while ((lines = reader.readLine()) != null) {
                sb.append(lines);
            }
            reader.close();
            connection.disconnect();

            tmpStrRet = sb.toString();
        } catch (Exception ex) {
            ex.printStackTrace();
            throw ex;
        } finally {
            if (reader != null) {
                reader.close();
            }
            if (connection != null) {
                connection.disconnect();
            }
        }

        return tmpStrRet;
    }

    protected String sendUnifiedOrder(HashMap<String, String> mapParams, ActSetItem actItem) throws Exception {
        String tmpStrRet = "";

        String signData = SignUtil.buildSignString(mapParams) + actItem.saltKey;
        WriteBankLogLn2("待签名原始数据:\r\n" + signData);

        String sign = SignUtil.signWithMd5(mapParams, actItem.saltKey, getCharset());
        mapParams.put("sign", sign); /* 签名 */

        String postReqStr = JSON.toJSONString(mapParams);
        WriteBankLogStep2(postReqStr);

        URL url = null;
        HttpURLConnection connection = null;
        BufferedReader reader = null;

        try {
            String postUrl = bankFront.getUrl("");
            WriteBankLogLn2("服务地址:" + postUrl);
            url = URLHelper.getUrl(postUrl);//new URL(postUrl);
            boolean enableProxy = FGBiz.dspCenter.dspSet.enableProxy;
            if(enableProxy){
                String proxyIP = FGBiz.dspCenter.dspSet.proxyIP;
                int proxyPort = Integer.parseInt(FGBiz.dspCenter.dspSet.proxyPort);

                SocketAddress sa = new InetSocketAddress(proxyIP, proxyPort);
                Proxy proxy = new Proxy(Proxy.Type.HTTP, sa);
                connection = (HttpURLConnection) url.openConnection(proxy);
            } else {
                connection = (HttpURLConnection) url.openConnection();
            }

            if (url.getProtocol().equals("https")) {
                HttpsURLConnection con = (HttpsURLConnection) connection;
                TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
                    public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                        return null;
                    }

                    public void checkClientTrusted(
                            java.security.cert.X509Certificate[] certs, String authType) {
                    }

                    public void checkServerTrusted(
                            java.security.cert.X509Certificate[] certs, String authType) {
                    }
                }};
                SSLContext sc = SSLContext.getInstance("SSL");
                sc.init(null, trustAllCerts, new java.security.SecureRandom());
                con.setSSLSocketFactory(sc.getSocketFactory());
                con.setHostnameVerifier(new HostnameVerifier() {
                    public boolean verify(String hostname, SSLSession session) {
                        return true;
                    }
                });
            }

            connection.setDoOutput(true);
            connection.setDoInput(true);
            connection.setRequestMethod("POST");
            connection.setUseCaches(false);
            connection.setInstanceFollowRedirects(true);
            connection.setRequestProperty("Content-Type", "application/json;charset=" + getCharset() + "");
            connection.setRequestProperty("Accept", "application/json");
            connection.connect();
            OutputStream out = connection.getOutputStream();
            out.write(postReqStr.getBytes(getCharset()));
            out.flush();
            out.close();
            reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), getCharset()));
            String lines;
            StringBuffer sb = new StringBuffer();
            while ((lines = reader.readLine()) != null) {
                sb.append(lines);
            }
            reader.close();
            connection.disconnect();
            tmpStrRet = sb.toString();
            WriteBankLogStep3(tmpStrRet);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw ex;
        } finally {
            if (reader != null) {
                reader.close();
            }
            if (connection != null) {
                connection.disconnect();
            }
        }

        return tmpStrRet;
    }

    protected String sendUnifiedOrder(HashMap<String, String> mapParams, ActSetItem actItem, String p_for) throws Exception {
        String tmpStrRet = "";

        String signData = SignUtil.buildSignString(mapParams) + actItem.saltKey;
        WriteBankLogLn2("待签名原始数据:\r\n" + signData);

        String sign = SignUtil.signWithMd5(mapParams, actItem.saltKey, getCharset());
        mapParams.put("sign", sign); /* 签名 */

        String postReqStr = JSON.toJSONString(mapParams);
        WriteBankLogStep2(postReqStr);

        URL url = null;
        HttpURLConnection connection = null;
        BufferedReader reader = null;

        try {
            String postUrl = bankFront.getUrl(p_for);
            WriteBankLogLn2("服务地址:" + postUrl);
            url = URLHelper.getUrl(postUrl);//new URL(postUrl);

            boolean enableProxy = FGBiz.dspCenter.dspSet.enableProxy;
            if(enableProxy){
                String proxyIP = FGBiz.dspCenter.dspSet.proxyIP;
                int proxyPort = Integer.parseInt(FGBiz.dspCenter.dspSet.proxyPort);

                SocketAddress sa = new InetSocketAddress(proxyIP, proxyPort);
                Proxy proxy = new Proxy(Proxy.Type.HTTP, sa);
                connection = (HttpURLConnection) url.openConnection(proxy);
            } else {
                connection = (HttpURLConnection) url.openConnection();
            }

            if (url.getProtocol().equals("https")) {
                HttpsURLConnection con = (HttpsURLConnection) connection;
                TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
                    public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                        return null;
                    }

                    public void checkClientTrusted(
                            java.security.cert.X509Certificate[] certs, String authType) {
                    }

                    public void checkServerTrusted(
                            java.security.cert.X509Certificate[] certs, String authType) {
                    }
                }};
                SSLContext sc = SSLContext.getInstance("SSL");
                sc.init(null, trustAllCerts, new java.security.SecureRandom());
                con.setSSLSocketFactory(sc.getSocketFactory());
                con.setHostnameVerifier(new HostnameVerifier() {
                    public boolean verify(String hostname, SSLSession session) {
                        return true;
                    }
                });
            }

            connection.setDoOutput(true);
            connection.setDoInput(true);
            connection.setRequestMethod("POST");
            connection.setUseCaches(false);
            connection.setInstanceFollowRedirects(true);
            connection.setRequestProperty("Content-Type", "application/json;charset=" + getCharset() + "");
            connection.setRequestProperty("Accept", "application/json");
            connection.connect();
            OutputStream out = connection.getOutputStream();
            out.write(postReqStr.getBytes(getCharset()));
            out.flush();
            out.close();
            reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), getCharset()));
            String lines;
            StringBuffer sb = new StringBuffer();
            while ((lines = reader.readLine()) != null) {
                sb.append(lines);
            }
            reader.close();
            connection.disconnect();
            tmpStrRet = sb.toString();
            WriteBankLogStep3(tmpStrRet);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw ex;
        } finally {
            if (reader != null) {
                reader.close();
            }
            if (connection != null) {
                connection.disconnect();
            }
        }

        return tmpStrRet;
    }

    protected String sendToBank(Map<String, String> p_reqMap, String url, ActSetItem actItem) throws Exception {
        String urlReqStr = "";
        for (Map.Entry<String, String> map : p_reqMap.entrySet()) {
            if (StringHelper.hasAnyChar(urlReqStr)) {
                urlReqStr += "&";
            }
            urlReqStr += map.getKey() + "=" + map.getValue();
        }

        WriteBankLogLn2("发送银行请求数据明文:\r\n" + urlReqStr);

        Charset encoding = Charset.forName(getCharset());
        BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("merchant", "merchant2014!"));
        HttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(RequestConfig.custom().setSocketTimeout(60000).build())
                .setDefaultConnectionConfig(ConnectionConfig.custom().setCharset(encoding).build())
                .setDefaultCredentialsProvider(credentialsProvider).build();

        HttpPost post = new HttpPost(url);
        RequestConfig.Builder customReq = RequestConfig.custom();
        customReq.setConnectTimeout(10000);
        customReq.setSocketTimeout(10000);
        boolean enableProxy = FGBiz.dspCenter.dspSet.enableProxy;
        if (enableProxy) {
            String proxyIP = FGBiz.dspCenter.dspSet.proxyIP;
            int proxyPort = Integer.parseInt(FGBiz.dspCenter.dspSet.proxyPort);
            HttpHost proxy = new HttpHost(proxyIP, proxyPort,"http");
            customReq.setProxy(proxy);
        }
        post.setConfig(customReq.build());
        byte[] encryptedData = encryptByRSA(urlReqStr.getBytes(encoding), actItem);
        post.setEntity(new ByteArrayEntity(encryptedData));

        HttpResponse response = httpClient.execute(post);
        byte[] respData = EntityUtils.toByteArray(response.getEntity());
        String tmpStrRet = decryptByRSA(respData, actItem);

        return tmpStrRet;
    }

    protected Map<String, String> convertToMap(String p_reqStr) {
        Map<String, String> tmpRetMap = new HashMap<String, String>();

        String[] tmpUrlArr = p_reqStr.split("&");
        for (String urlStr : tmpUrlArr) {
            int index = urlStr.indexOf("=");
            tmpRetMap.put(urlStr.substring(0, index), urlStr.substring(index + 1));
        }

        return tmpRetMap;
    }

    protected byte[] encryptByRSA(byte[] p_reqBytes, ActSetItem actItem) throws Exception {
        KeyStore ks = KeyStore.getInstance("jks");
        FileInputStream fis = new FileInputStream(actItem.ownKeyStorePath);

        char[] keyPassword = null;
        if (StringHelper.hasAnyChar(actItem.ownKeyPassword)) {
            keyPassword = actItem.ownKeyPassword.toCharArray();
        }
        ks.load(fis, keyPassword);
        fis.close();
        fis = null;

        @SuppressWarnings("rawtypes")
        Enumeration enumAlias = ks.aliases();

        String keyAlias = null;
        if (enumAlias.hasMoreElements()) {
            keyAlias = (String) enumAlias.nextElement();
        }

        PrivateKey privateKey = (PrivateKey) ks.getKey(keyAlias, keyPassword);

        if (privateKey == null) {
            return null;
        }

        byte[] encryptData = EncryptUtils.encrypt(p_reqBytes, privateKey);

        return encryptData;
    }

    protected String decryptByRSA(byte[] p_reqBytes, ActSetItem actItem) throws Exception {
        KeyStore ks = KeyStore.getInstance("jks");
        FileInputStream fis = new FileInputStream(actItem.ownKeyStorePath);

        char[] keyPassword = null;
        if (StringHelper.hasAnyChar(actItem.ownKeyPassword)) {
            keyPassword = actItem.ownKeyPassword.toCharArray();
        }
        ks.load(fis, keyPassword);
        fis.close();
        fis = null;

        @SuppressWarnings("rawtypes")
        Enumeration enumAlias = ks.aliases();

        String keyAlias = null;
        if (enumAlias.hasMoreElements()) {
            keyAlias = (String) enumAlias.nextElement();
        }

        PrivateKey privateKey = (PrivateKey) ks.getKey(keyAlias, keyPassword);

        if (privateKey == null) {
            return null;
        }

        byte[] decryptData = EncryptUtils.decrypt(p_reqBytes, privateKey);

        return new String(decryptData, getCharset());
    }

    protected String[] getChinaUMSSign(String plian, String md5Key) {
        String[] tmpStrRet = new String[]{"", ""};

        Map<String, String> params = new HashMap<String, String>();
        String[] nodes = plian.split("&");
        for (String node : nodes) {
            int index = node.indexOf("=");
            String key = node.substring(0, index);
            String value = node.substring(index + 1);
            params.put(key, value);
        }

        tmpStrRet[0] = SignUtil.buildSignString(params) + md5Key;
        tmpStrRet[1] = params.get("sign");
        return tmpStrRet;
    }

    public boolean verifyWithMd5(String originStr, String sign) {
        String tmpSign = null;
        try {
            tmpSign = DigestUtils.md5Hex(originStr.getBytes("utf-8")).toUpperCase();
            WriteBankLogLn2("3.2 本地签名:" + tmpSign);
            if (sign.equals(tmpSign)) {
                return true;
            } else {
                return false;
            }
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return false;
        }
    }

    public String buildLen(String p_reqStr, int realLen) throws IOException {
        int len = p_reqStr.getBytes("GBK").length;
        String realChar = String.format(("%-" + (realLen - len) + "s"), "");

        return p_reqStr + realChar;
    }

    /**
     * 按字节截取字符串避免半个汉字
     *
     * @param str
     * @param num
     * @return
     * @throws IOException
     */
    public String cutCountLen(String str, int num) throws IOException {
        int count = 0;
        byte[] b = str.getBytes("GBK");
        for (int i = 0; i < num; i++) {
            if (b[i] < 0) {
                count++;
            }
        }
        //因为是GBK，所有模2来判断
        if (count % 2 == 0) {
            return new String(b, 0, num, "GBK");
        } else {
            return new String(b, 0, num - 1, "GBK");
        }
    }

    /**
     * Excel解析读取
     *
     * @param filepath
     * @return
     * @throws Exception
     */
    public String readExcel(String filepath) throws Exception {
        try {
            Workbook wb = new HSSFWorkbook(new FileInputStream(filepath));
            Sheet sheet = wb.getSheetAt(0);

            StringBuilder sbFileContent = new StringBuilder();
            for (int i = 2; i < sheet.getLastRowNum(); i++) {
                Row detailRow = sheet.getRow(i);
                if (detailRow == null) {// 略过空行
                    continue;
                }
                if (sbFileContent.length() > 0) {
                    sbFileContent.append("\r\n");
                }
                int cellSize = detailRow.getLastCellNum();
                StringBuilder eachline = new StringBuilder();
                for (int k = 0; k < cellSize; k++) {
                    Cell cell = detailRow.getCell(k);
                    if (eachline.length() > 0) {
                        eachline.append(",");
                    }
                    eachline.append(getCellValue(cell));
                }
                sbFileContent.append(eachline);
            }
            return sbFileContent.toString();
        } catch (FileNotFoundException e) {
            return "";
        }
    }

    /**
     * 获取Excel某列的值
     *
     * @param cell
     * @return
     */
    public static String getCellValue(Cell cell) {
        String cellValue = "";
        if (cell == null) {
            return cellValue;
        }

        //把数字当成String来读，避免出现1读成1.0的情况  
        if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
            if (org.apache.poi.ss.usermodel.DateUtil.isCellDateFormatted(cell)) {
                Date theDate = cell.getDateCellValue();
                SimpleDateFormat dff = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                cellValue = dff.format(theDate);
            } else {
                cell.setCellType(Cell.CELL_TYPE_STRING);
            }
        }

        //判断数据的类型  
        switch (cell.getCellType()) {
            case Cell.CELL_TYPE_NUMERIC: //数字
                if (org.apache.poi.ss.usermodel.DateUtil.isCellDateFormatted(cell)) {
                    Date theDate = cell.getDateCellValue();
                    SimpleDateFormat dff = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    cellValue = dff.format(theDate);
                } else {
                    cellValue = String.valueOf(cell.getNumericCellValue());
                }
                break;
            case Cell.CELL_TYPE_STRING: //字符串  
                cellValue = String.valueOf(cell.getStringCellValue());
                break;
            case Cell.CELL_TYPE_BOOLEAN: //Boolean  
                cellValue = String.valueOf(cell.getBooleanCellValue());
                break;
            case Cell.CELL_TYPE_FORMULA: //公式  
                cellValue = String.valueOf(cell.getCellFormula());
                break;
            case Cell.CELL_TYPE_BLANK: //空值   
                cellValue = "";
                break;
            case Cell.CELL_TYPE_ERROR: //故障  
                cellValue = "非法字符";
                break;
            default:
                cellValue = "未知类型";
                break;
        }
        return cellValue;
    }

    public Map<String, String> removeHead(Map<String, String> tmpMapParams) {
        tmpMapParams.remove("BankCode");
        tmpMapParams.remove("TransType");
        tmpMapParams.remove("CommandCode");
        tmpMapParams.remove("Entity");
        return tmpMapParams;
    }

    protected String getSignStr(Map<String, String> mapParams) {
        Map<String, String> signMap = new HashMap<String, String>();

        for (Map.Entry<String, String> entry : mapParams.entrySet()) {
            String name = entry.getKey();
            String value = entry.getValue();

            if (StringHelper.hasAnyChar(value)) {
                signMap.put(name, value);
            }
        }

        // Map排序
        signMap = SortHelper.sortMapByName(signMap);

        // Map转HTTP字符串
        String signStr = "";
        for (String key : signMap.keySet()) {
            signStr += "&" + key + "=" + signMap.get(key);
        }
        signStr = signStr.substring(1);

        return signStr;
    }

    String authorization;

    public static byte[] hmacSHA256(byte[] data, byte[] key) throws NoSuchAlgorithmException, InvalidKeyException {
        String algorithm = "HmacSHA256";
        Mac mac = Mac.getInstance(algorithm);
        mac.init(new SecretKeySpec(key, algorithm));
        return mac.doFinal(data);
    }

    public String getOpenBodySig(String appId, String appKey, String content) throws Exception {
        WriteBankLogLn("加密前报文明文:\r\n" + content);
        String timestamp = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
        String nonce = UUID.randomUUID().toString().replace("-", "");
        String str1_C = appId + timestamp + nonce + DigestUtils.sha256Hex(new ByteArrayInputStream(content.getBytes()));

        byte[] localSignature = hmacSHA256(str1_C.getBytes(), appKey.getBytes());
        return ("OPEN-BODY-SIG AppId=" + "\"" + appId + "\"" + ", Timestamp=" + "\"" + timestamp + "\"" + ", Nonce=" + "\"" + nonce + "\"" + ", Signature=" + "\"" + Base64.encodeBase64String(localSignature) + "\"");
    }

    public String getOpenBodySigForNetpay(String appId, String appKey, String timestamp, String nonce, String content) throws Exception {

        String str1_C = appId + timestamp + nonce + DigestUtils.sha256Hex(new ByteArrayInputStream(content.getBytes()));
        byte[] localSignature = hmacSHA256(str1_C.getBytes(), appKey.getBytes());

        return ("authorization=OPEN-FORM-PARAM" + "&appId=" + appId + "&timestamp=" + timestamp + "&nonce=" + nonce + "&content=" + URLEncoder.encode(content, "UTF-8") + "&signature=" + URLEncoder.encode(Base64.encodeBase64String(localSignature), "UTF-8"));
    }

    public String submitSend(String url, String content, ActSetItem actItem) throws Exception {
        WriteBankLogLn2("加密前报文明文:\r\n" + content);
        String entity = getOpenBodySigForNetpay(actItem.appId, actItem.appKey, Format.DateTime14Format.format(new Date()), UUID.randomUUID().toString().replace("-", ""), content);
        return url + "?" + entity;
    }

    public String querySend(String url, String content, ActSetItem actItem) throws Exception {
        String authorization = getOpenBodySig(actItem.appId, actItem.appKey, content);
        CloseableHttpClient httpClient = HttpClients.createDefault();
        WriteBankLogLn2("服务地址:" + url);
        HttpPost httpPost = new HttpPost(url);
        httpPost.setHeader("Authorization", authorization);
        RequestConfig.Builder customReq = RequestConfig.custom();
        customReq.setConnectTimeout(10000);
        customReq.setSocketTimeout(10000);
        boolean enableProxy = FGBiz.dspCenter.dspSet.enableProxy;
        if (enableProxy) {
            String proxyIP = FGBiz.dspCenter.dspSet.proxyIP;
            int proxyPort = Integer.parseInt(FGBiz.dspCenter.dspSet.proxyPort);
            HttpHost proxy = new HttpHost(proxyIP, proxyPort,"http");
            customReq.setProxy(proxy);
        }
        httpPost.setConfig(customReq.build());
        StringEntity se = new StringEntity(content, "UTF-8");
        se.setContentType("application/json");
        httpPost.setEntity(se);
        CloseableHttpResponse response = httpClient.execute(httpPost);
        HttpEntity entity1 = response.getEntity();
        String resStr = null;
        if (entity1 != null) {
            resStr = EntityUtils.toString(entity1, "UTF-8");
        }
        WriteBankLogStep3(resStr);
        httpClient.close();
        response.close();
        return resStr;
    }

}
